<template>
	<view class="my-wrapper">
		<view class="status_bar"></view>
		<view class="header" @click="userDetail">
			<div class="vip-box" @click.stop="navigateTo('/pages/tabbar/user/vip/vip')"
				style="display: flex;justify-content: center;">
				<image v-if="myCard" class="vipimgs" :src="myCard"></image>
				<image v-else class="vipimgs"
					src="https://rsyl.oss-cn-beijing.aliyuncs.com/3b01b23ccfc741f4ae97990ad32ac55f.png"></image>
			</div>
			<div
				style="display: flex;justify-content: center;font-size: 32rpx;color: #fff;font-weight: bold;margin-top: -40rpx;">
				我的</div>
			<div style="display: flex; justify-content: space-between;margin-top: 8%;">
				<view class="head-1">
					<image :src="userInfo.face"></image>
				</view>
				<view class="head-2" v-if="userInfo.id">
					<view class="user-name">
						<view class="uservip">
							<view class='tag pt' v-if='userInfo.gradeName=="0"'>{{rate['0'].name}}</view>
							<view v-if='userInfo.gradeName=="1"'>
								<image class='svip' src="/static/myimg/yinvip.png"></image>
							</view>
							<view v-if='userInfo.gradeName=="2"'>
								<image class='svip' src="/static/myimg/jinvip.png"></image>
							</view>
						</view>
						<view>{{ userInfo.nickName}}</view>
						<view class="vip">
							<view class='tag city' v-if='userInfo.partnerType==4'>城市合伙人</view>
							<view class='tag sy' v-else-if='userInfo.partnerType==1'>事业合伙人</view>
							<view class='tag ts' v-else-if="userInfo.partnerType===2||userInfo.haveStore===true">天使合伙人
							</view>
							<view class='tag pt' v-else-if='userInfo.partnerType==3'>推广员</view>
						</view>
					</view>
					<view class="partner">
						<view class="time"
							v-if="userInfo.partnerEndTime&&userInfo.partnerType==4||userInfo.partnerType==1||userInfo.partnerType===2">
							截至: {{ userInfo.partnerEndTime}}</view>
						<view class="time" v-else>截至: {{ userInfo.gradeEndTime}}</view>
					</view>
				</view>
				<view class="head-2" v-else>
					<view class="user-name">登录/注册</view>
				</view>
				<u-icon style="display: flex;align-items: center;" name="arrow-right"></u-icon>
			</div>
			<div class="pointmoney box">
				<div class="money-wrapper">
					<div
						v-if="userInfo.partnerType == 1 || userInfo.partnerType == 2 || userInfo.partnerType == 4 || userInfo.partnerType == 3">
						<div class="wallet-list">
							<div class="item" @click.stop="chongming">
								<view class="mineyyu">
									<image src="/static/hb.png" mode="aspectFill" class="image"></image>
									<view class="money">{{ walletNum | unitPrice}}</view>
								</view>
								<view class="chongzhi">余额钱包</view>
							</div>
							<div class="item" v-if="userInfo.haveStore == true" @click.stop="xiaoshou">
								<view class="mineyyu">
									<image src="/static/hb.png" mode="aspectFill" class="image"></image>
									<view class="money">{{ flowpriceSum | unitPrice}}</view>
								</view>
								<view class="chongzhi">销售钱包</view>
							</div>
							<div class="item" v-if="userInfo.partnerType == 1 || userInfo.partnerType == 2"
								@click.stop="tuiming">
								<view class="mineyyu">
									<image src="/static/hb.png" mode="aspectFill" class="image"></image>
									<view class="money">{{ tuiguangSum | unitPrice}}</view>
								</view>
								<view class="chongzhi">推广钱包</view>
							</div>
							<div class="item" v-if="userInfo.partnerType == 4" @click.stop="huiming">
								<view class="mineyyu">
									<image src="/static/hb.png" mode="aspectFill" class="image"></image>
									<view class="money">{{ tuiguanghuiyuan | unitPrice}}</view>
								</view>
								<view class="chongzhi" style="font-size: 24rpx;">推广钱包-会员费</view>
							</div>
							<div class="item" v-if="userInfo.partnerType == 4" @click.stop="fuming">
								<view class="mineyyu">
									<image src="/static/hb.png" mode="aspectFill" class="image"></image>
									<view class="money">{{ tuiguangfuwu | unitPrice}}</view>
								</view>
								<view class="chongzhi" style="font-size: 24rpx;">推广钱包-服务费</view>
							</div>
						</div>
						<div class="box"
							style="display: flex; flex: 1; align-items: center; justify-content: space-around;margin-top: 5%;">
							<span class="Recharge" @click.stop="chongzhi">充值</span>
							<span
								v-if="userInfo.partnerType == 1 || userInfo.partnerType == 2 || userInfo.partnerType == 4 || userInfo.partnerType == 3"
								class="Withdrawal" @click.stop="Withdrawal">提现</span>
							<span
								v-if="userInfo.partnerType == 1 || userInfo.partnerType == 2 || userInfo.partnerType == 4 || userInfo.partnerType == 3"
								class="accounts" @click.stop="zhuanzhang">转赠</span>
						</div>
					</div>
					<div v-else
						style="display: flex;justify-content: space-around;align-items: center;margin-bottom: 8%;margin-top: 7%;">
						<div class="item" @click.stop="chongming">
							<view class="mineyyu">
								<image src="/static/hb.png" mode="aspectFill" class="image"></image>
								<view class="money">{{ walletNum | unitPrice}}</view>
							</view>
							<view class="chongzhi">余额钱包</view>
						</div>
						<div class="box" style="margin-top: 100rpx;">
							<span class="Recharge" @click.stop="chongzhi">充值</span>
						</div>
					</div>

				</div>
			</div>
		</view>
		<div class="pointBox box">
			<!-- 我的订单，代付款 -->
			<view class="myorder">
				<view class="wode">订单</view>
				<view class="upgrade" @click="navigateTo('/pages/order/myOrder?status=0')">全部订单</view>
			</view>
			<view class="order">
				<view class="order-item" @click="navigateTo('/pages/order/myOrder?status=1')">
					<image class="image" src="/static/myimg/waitpay.png" mode=""></image>
					<view style="color: rgba(36, 36, 36, 1);">待付款</view>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/myOrder?status=3')">
					<image class="image" src="/static/myimg/waitshou.png" mode=""></image>
					<view style="color: rgba(36, 36, 36, 1);">待收货</view>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/evaluate/myEvaluate?tab=1')">
					<image class="image" src="/static/myimg/waitping.png" mode=""></image>
					<view style="color: rgba(36, 36, 36, 1);">待评价</view>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/afterSales/afterSales')">
					<image class="image" src="/static/myimg/shouhou.png" mode=""></image>
					<view style="color: rgba(36, 36, 36, 1);">售后服务</view>
				</view>
			</view>
		</div>
		<!-- 常用工具 -->
		<tool ref="tools" @refresh='refreshUserinfo' />
	</view>
</template>
<script>
	import {
		getCountSum,
	} from "@/api/withdrawal.js";
	import tool from "@/pages/tabbar/user/utils/tool.vue";
	import {
		getCouponsNum,
		getFootprintNum,
		GetCommission,
		GetStoreStatus,
		GetStoreFeeStatus,
		getUserInfo,
		VIPRateSetting
	} from "@/api/members.js";
	import {
		getUserWallet
	} from "@/api/members";
	import storage from "@/utils/storage.js";
	import {
		getPictureList
	} from "@/api/article";
	import gkcity from "@/components/m-city/m-city.vue";
	export default {
		components: {
			tool,
			"m-city": gkcity,
		},
		data() {
			return {
				myCard:'',
				title: '我的',
				businessState: '',
				userInfo: {},
				couponNum: 0,
				footNum: 0,
				walletNum: 0, //焕贝余额
				tgMoney: 0, //推广钱包余额
				rate: {},
				flowpriceSum: 0, // 销售钱包余额
				tuiguangSum: 0, // 推广钱包余额
				tuiguangfuwu: 0, // 推广钱包服务费
				tuiguanghuiyuan: 0, // 推广钱包会员费
			};
		},
		onLoad() {},
		onShow() {
			getPictureList({
				code: 'my_card'
			}).then(res=>{
				this.myCard=res.data.result[0].content
			})
			// 判断是否登录
			if (this.$options.filters.isLogin("auth")) {
				// this.getUserOrderNum();
				this.getwithyue()
				this.getwithdrawApply()
				this.gettuiguang()
				this.chengtuifu()
				this.chengtuihui()
				// 会员汇率
				this.rate = storage.getVipRate()
				Promise.all([
					GetStoreStatus(), // 店铺状态
					GetStoreFeeStatus(), // 有无支付年费
					getUserInfo(), // 用户个人信息
				]).then((res) => {
					// --0--
					this.businessState = res[0].data.result || {}
					if (this.businessState.storeByMember == 'OPEN' && [1, 4].indexOf(this.userInfo.partnerType) <
						0) {
						this.userInfo.partnerType = 2
					}
					// --2--
					if (res[2].data.code === 200) {
						this.userInfo = res[2].data.result
						storage.setUserInfo(res[2].data.result);

					} else {
						this.userInfo = {}
						this.$options.filters.clearAllStorage()
						storage.setHasLogin(false)
					}
					if (this.$refs.tools) {
						this.$refs.tools.init()
					}

					storage.setBusiness(this.businessState);
					storage.setUserInfo(this.userInfo);
					if (this.$refs.tools) {
						this.$refs.tools.init()
					}
				});
			} else {
				this.initData()
			}
			if (this.$refs.tools) {
				this.$refs.tools.init()
			}
		},
		mounted() {},
		onPullDownRefresh() {
			// this.getUserOrderNum();
			this.userInfo = this.$options.filters.isLogin();
		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navigateTo("/pages/mine/set/setUp");
			}
		},
		// #endif
		methods: {
			// 打电话
			daphone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone,
				});
			},
			// 余额钱包明细
			chongming() {
				this.navigateTo("/pages/mine/withdrawal/moneyhistory?type=" + 'RECHARGE');
			},
			// 销售钱包明细
			xiaoshou() {
				this.navigateTo("/pages/mine/withdrawal/moneyhistory?type=" + 'SALE');
			},
			// 推广钱包明细
			tuiming() {
				this.navigateTo("/pages/mine/withdrawal/moneyhistory?type=" + 'PROMOTE');
			},
			// 推广钱包会员费明细
			huiming() {
				this.navigateTo("/pages/mine/withdrawal/moneyhistory?type=" + 'PROMOTE_HY');
			},
			// 推广钱包服务费明细
			fuming() {
				this.navigateTo("/pages/mine/withdrawal/moneyhistory?type=" + 'PROMOTE_FW');
			},
			// 查询余额钱包余额
			getwithyue() {
				let parse = {
					owner: 'RECHARGE'
				}
				getCountSum(parse).then((res) => {
					if (res.data.code == 200) {
						this.walletNum = res.data.result.memberWallet
					}
				});
			},
			// 查询销售钱包余额
			getwithdrawApply() {
				let parse = {
					owner: 'SALE'
				}
				getCountSum(parse).then((res) => {
					if (res.data.code == 200) {
						this.flowpriceSum = res.data.result.memberWallet
					}
				});
			},
			// 查询推广钱包余额
			gettuiguang() {
				let parse = {
					owner: 'PROMOTE'
				}
				getCountSum(parse).then((res) => {
					if (res.data.code == 200) {
						this.tuiguangSum = res.data.result.memberWallet
					}
				});
			},
			// 查询推广钱包服务费
			chengtuifu() {
				let parse = {
					owner: 'PROMOTE_FW'
				}
				getCountSum(parse).then((res) => {
					if (res.data.code == 200) {
						this.tuiguangfuwu = res.data.result.memberWallet
					}
				});
			},
			// 查询推广钱包会员费
			chengtuihui() {
				let parse = {
					owner: 'PROMOTE_HY'
				}
				getCountSum(parse).then((res) => {
					if (res.data.code == 200) {
						this.tuiguanghuiyuan = res.data.result.memberWallet
					}
				});
			},
			// 提现跳转
			Withdrawal() {
				// 1.是否登录
				let loginState = storage.getHasLogin();
				if (!loginState) {
					this.$options.filters.forceLogin()
				} else {
					this.navigateTo("/pages/mine/withdrawal/index")
				}
			},
			// 转账跳转
			zhuanzhang() {
				// 1.是否登录
				let loginState = storage.getHasLogin();
				if (!loginState) {
					this.$options.filters.forceLogin()
				} else {
					this.navigateTo("/pages/partner/transfer-accounts/transfer-accounts")
				}
			},
			// 充值跳转
			chongzhi() {
				// 1.是否登录
				let loginState = storage.getHasLogin();
				if (!loginState) {
					this.$options.filters.forceLogin()
				} else {
					this.navigateTo("/pages/mine/deposit/recharge")
				}
			},
			// 初始化数据  清空信息
			initData() {
				this.businessState = '';
				this.userInfo = {};
				this.couponNum = 0;
				this.footNum = 0;
				this.walletNum = 0;
				this.tgMoney = 0;
				this.flowpriceSum = 0;
				this.tuiguangSum = 0;
				this.tuiguangfuwu = 0;
				this.tuiguanghuiyuan = 0;
				this.rate = {}
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navigateTo(url) {
				uni.navigateTo({
					url,
				});
			},
			userDetail() {
				if (this.$options.filters.isLogin('auth')) {
					this.navigateTo("/pages/mine/set/personMsg")
				} else {
					this.$options.filters.navigateToLogin()
				}
			},
			refreshUserinfo() {
				this.initUserInfo()
			},
			// 获取个人信息
			initUserInfo() {
				//获取用户信息
				getUserInfo().then((user) => {
					if (user.data.code === 200) {
						this.userInfo = user.data.result
						storage.setUserInfo(user.data.result);
					} else {
						this.userInfo = {}
						storage.removeUserInfo()
						storage.setHasLogin(false)
					}
					if (this.$refs.tools) {
						this.$refs.tools.init()
					}
				});
			}
		},
	};
</script>
<style lang="scss" scoped>
	.my-wrapper {

		.register {
			color: $weChat-color !important;
			border: none !important;
			background: #fff !important;
		}

		.header {
			position: relative;
			width: 100%;
			padding: 60px 30rpx 120upx;
			background-size: cover;
			border-bottom-left-radius: 30rpx;
			border-bottom-right-radius: 30rpx;
			background-image: url('https://rsyl.oss-cn-beijing.aliyuncs.com/f35782c7a88f4ec8b601245b041ab92f.png');
			background-position: bottom;
			background-repeat: no-repeat;
			color: #ffffff;

			.vip-box {
				position: absolute;
				bottom: 0;
				width: 700upx;
				left: 25upx;
			}

			.head-1 {
				text-align: center;
				width: 152rpx;
				position: relative;
				display: flex;
				align-items: center;
				margin-right: 24upx;

				image {
					width: 152rpx;
					height: 144rpx;
					border-radius: 50%;
					border: 3px solid #fff;
				}

				.edti-head {
					position: absolute;
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					background-color: rgba(255, 255, 255, 0.3);
					top: 100rpx;
					right: 0;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.head-2 {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;

				.user-name {
					display: flex;
					font-size: 34rpx;
				}

				.vip {
					margin-left: 8upx;
				}

				.partner {
					font-size: 24upx;
					margin-top: 12upx;
					display: flex;

					.time {
						margin-left: 8upx;
					}
				}

				.tag {
					width: 140upx;
					height: 40upx;
					line-height: 40upx;
					text-align: center;
					font-size: 24upx;
					border-radius: 8upx;

					&.pt {
						color: #616161;
						background-image: linear-gradient(to right, #b8c1c6, #dfddd9);
						margin-left: 10upx;
					}

					&.ts {
						color: #fff;
						background: rgba(216, 33, 2, 1);
						margin-left: 10upx;
						// background-image: linear-gradient(to right, #faa7c1, #f1cbdb);
					}



					&.sy {
						color: #fff;
						background-image: linear-gradient(to right, #fac671, #f1d7aa);
						margin-left: 10upx;
					}

					&.city {
						color: #b9b425;
						background-image: linear-gradient(to right, #222222, #999999);
						margin-left: 10upx;
					}


				}
			}
		}

		.money-wrapper {
			margin-bottom: 24upx;

			.wallet-list {
				display: flex;
				align-items: center;
				justify-content: space-around;

				.item {
					flex: 0 0 33.3%;
					width: 33.3%;
				}
			}

			.mymoney {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 10upx;
				border-bottom: 1px solid #f1f1f1;
				padding-left: 3%;
				padding-right: 3%;

				.wode {
					padding-bottom: 20upx;
					color: #FFFFFF;
					font-size: 36upx;
				}

				.upgrade {
					padding-bottom: 20upx;
					color: #FFFFFF;
					font-size: 36upx;
				}

				.huiyuan {
					padding-bottom: 20upx;
				}
			}

			.item {
				// flex: 1;
				color: #FFFFFF;
				display: flex;
				flex-direction: column;
				justify-content: center;
				// align-items: center;
				height: 100upx;
				// text-align: center;
				margin-top: 10%;
				padding-bottom: 3%;
				// color: #fff;
				// padding-left: 3%;
				// padding-right: 3%;
				// width: 30%;
				align-items: center;



				.mineyyu {
					display: flex;
					align-items: baseline;
					padding-top: 20upx;

					.money {
						color: rgba(255, 255, 255, 1);
						font-size: 36rpx;
						padding-left: 10upx;
						font-weight: bold;
					}

					.chongzhi {
						font-size: 24rpx;
						color: rgba(255, 255, 255, 1);
						margin-top: 3%;
					}

					.image {
						width: 40upx;
						height: 20upx;
					}
				}
			}
		}

		.pointmoney {
			width: 100%;
			padding: 0 3%;
			box-sizing: border-box;
			// margin: 0 3% 24upx;
			// position: absolute;
			// top: 35%;
			// background: #444444;
			// border-radius: 20rpx;
			// box-shadow: 0 4rpx 24rpx 0 rgba($color: #464646, $alpha: 1);
		}

		.pointBox {
			width: 94%;
			margin: 50upx 3% 24upx;
			background: #fff;
			border-radius: 20rpx;
			box-shadow: 0 4rpx 24rpx 0 rgba($color: #f6f6f6, $alpha: 1);
		}

		.box {
			transform: translateY(-30rpx);
		}

		.order {
			height: 140rpx;
			text-align: center;
			font-size: $font-sm;
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 0 3%;
			color: rgba(36, 36, 36, 1);

			.order-item {
				flex: 1;
				text-align: center;

				.image {
					width: 80upx;
					height: 80upx;
				}

			}
		}
	}

	.Recharge {
		display: block;
		padding: 20upx 40upx;
		background: linear-gradient(90deg, rgba(251, 209, 110, 1) 0%, rgba(232, 171, 2, 1) 100%);
		color: #fff;
		border-radius: 16px;
		font-size: 12px
	}

	.accounts {
		display: block;
		padding: 20upx 40upx;
		background: linear-gradient(90deg, rgba(110, 152, 250, 1) 0.53%, rgba(43, 107, 227, 1) 100%);
		color: #fff;
		border-radius: 16px;
		font-size: 12px
	}

	.Withdrawal {
		display: block;
		padding: 20upx 40upx;
		background: linear-gradient(90deg, rgba(250, 157, 110, 1) 0%, rgba(227, 52, 43, 1) 100%);
		color: #fff;
		border-radius: 16px;
		font-size: 12px
	}

	.vipimgs {
		width: 100%;
		height: 130rpx;
		margin-top: 3.5%;
	}

	.myorder {
		display: flex;
		flex: 1;
		align-items: center;
		justify-content: space-between;
		padding: 26rpx 3%;
		border-bottom: 2rpx solid rgba(245, 249, 250, 1);

		.wode {
			font-size: 30rpx;
			color: rgba(36, 36, 36, 1);
			font-weight: bold;
		}

		.upgrade {
			font-size: 24rpx;
			color: rgba(177, 177, 177, 1);
		}
	}

	.uservip {
		margin-right: 10rpx;

		.svip {
			width: 40rpx;
			height: 40rpx;
		}
	}
</style>
